axios.interceptors.response.use(function (response) { let {status,message} = response.data;
  if (status === 1) layer.msg(message); 
    // 对响应数据做点什么
    return response;
  }, function (error) {
      let {status,message} = error.response.data;
      if (status === 1 && message === '身份认证失败！') {
          localStorage.removeItem('token');
          location.href = './login.html'
      }
      layer.msg(message);
    // 对响应错误做点什么
      return Promise.reject(error);
  });
function getUserInfo() {
    axios.get('http://www.itcbc.com:8080/my/user/userinfo',{
    headers: {
        Authorization: localStorage.getItem('token')
    }
}).then(res => {
    let {nickname,user_pic,username}= res.data.data;
    let name = nickname || username;
    $('.username').text(name);
    if (user_pic) {
        $('.layui-nav-img').attr('src',user_pic).show()
    } else {
        let first = name.substring(0,1).toUpperCase();
        $('.user-avatar').text(first).css('display','inline-block')
    }
})
}
getUserInfo();
$('#logout').on('click',function() {
    layer.confirm('你确定退出吗？',{icon:3,title:'提示'},function(index) {
        localStorage.removeItem('token');
        location.href = './login.html';
        layer.close(index);
    })
})